package com.itheima.advantagesup.mapper;

import com.itheima.advantagesup.entity.SysMenu;
import com.itheima.advantagesup.vo.MenuVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * SysMenuMapper
 *
 * @author liliudong
 * @version 1.0
 * @description
 * @date 2023/7/26 17:57
 */
@Mapper
public interface SysMenuMapper {
    /**
     * 选择列表按角色id
     *
     * @param roleIds 角色ids
     * @return {@link List}<{@link SysMenu}>
     */
    List<SysMenu> selectListByRoleIds(List<String> roleIds);

    /**
     *获取所有菜单
     */
    @Select("select * from sys_menu")
    List<SysMenu> getAll();

    @Insert("insert into sys_menu(pid, path,component,title,icon,is_show,is_cache,is_link,redirect,create_date,update_date,type,sort,mark,default_data) values " +
            "(#{pid},#{path},#{component},#{title},#{icon},#{isShow},#{isCache},#{isLink},#{redirect},#{createDate},#{updateDate},#{type},#{sort},#{mark},#{defaultData})")
    void add(SysMenu sysMenu);

    /**
     * 删除菜单成员
     * @param id
     */
    @Delete("delete from sys_menu where id = #{id}")
    void delete(Integer id);

    @Select("select * from sys_menu where pid = #{pid}")
    List<MenuVO> getMenuByPid(Integer pid);

    /**
     * 修改菜单
     * @param sysMenu
     */
    void update(SysMenu sysMenu);

    /**
     * 根据id查询菜单
     * @param id
     * @return {@link SysMenu}
     */
    @Select("select * from sys_menu where id = #{id}")
    SysMenu findById(Integer id);
}
